#pragma once

#include "chunk.hpp"
#include <cstdint>

namespace limbo {

struct Result {
  static Result make_error(uint32_t error_code, void *state,
                           Chunk consumed = {});
  static Result make_consumed(void *state, Chunk consumed);
  static Result make_demand(void *state, uint32_t need_bytes);

  operator bool() const { return error_code_ == 0; }
  uint32_t error_code() { return error_code_; }
  void *state() { return state_; }
  uint32_t demand() { return need_bytes_; }
  const Chunk &consumed() { return consumed_; }

  void merge(Chunk container) { consumed_ = container; }

private:
  Result(uint32_t error_code, void *state, const Chunk &consumed,
         uint32_t need_bytes);
  uint32_t error_code_;
  void *state_;
  Chunk consumed_;
  uint32_t need_bytes_;
};

} // namespace limbo
